<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('web_article', function (Blueprint $table) {
            $table->id();
            $table->integer('menus_id')->default(0)->comment('栏目Id');
            $table->string('tags', 255)->default('')->comment('文章标签');
            $table->string('title', 255)->default('')->comment('文章标题');
            $table->string('image',1000)->default('')->comment('封面图');
            $table->tinyInteger('is_image')->default(0)->comment('封面图类型:0=无图,1=单图,2=多图');
            $table->string('description', 255)->default('')->comment('介绍');
            $table->longText('content')->comment('文章内容');
            $table->string('seo_title', 80)->default('')->comment('SEO标题');
            $table->string('seo_keywords', 100)->default('')->comment('SEO关键词');
            $table->string('seo_description', 200)->default('')->comment('SEO介绍');
            $table->integer('pv')->default(0)->comment('页面访问量');
            $table->integer('uv')->default(0)->comment('独立访问用户数');
            $table->integer('like')->default(0)->comment('点赞数');
            $table->integer('sort')->default(0)->comment('排序（值越大越靠前）');
            $table->tinyInteger('status')->default(0)->comment('状态:1=正常,2=禁用');
            $table->tinyInteger('is_delete')->default(0)->comment('是否删除:1=删除,0=正常');
            $table->integer('created_at')->default(0)->comment('创建时间');
            $table->integer('updated_at')->default(0)->comment('修改时间');
        });
        DB::statement("ALTER TABLE `web_article` comment '【网站】文章管理'");
        $list_id = DB::table('admin_menus')->insertGetId([
            'name'        => '文章管理',
            'path'        => 'arts/manage/web_article',
            'icon'        => 'el-icon-document',
            'module_type' => 'extend',
            'level'       => 1,
            'facility'    => 1,
            'sort'        => 255,
            'status'      => 1,
            'created_at'  => time()
        ]);
        DB::table('admin_menus')->insert([
            [
                'parent_id'   => $list_id,
                'name'        => '新增',
                'path'        => 'arts/manage/web_article/insert',
                'action'      => 'insert',
                'icon'        => 'el-icon-circle-plus-outline',
                'level'       => 2,
                'facility'    => 2,
                'sort'        => 255,
                'status'      => 1,
                'created_at'  => time()
            ],
            [
                'parent_id'   => $list_id,
                'name'        => '编辑',
                'path'        => 'arts/manage/web_article/update',
                'action'      => 'update',
                'icon'        => 'el-icon-edit',
                'level'       => 2,
                'facility'    => 2,
                'sort'        => 255,
                'status'      => 1,
                'created_at'  => time()
            ],
            [
                'parent_id'   => $list_id,
                'name'        => '删除',
                'path'        => 'arts/manage/web_article/remove',
                'action'      => 'remove',
                'icon'        => 'el-icon-delete',
                'level'       => 2,
                'facility'    => 2,
                'sort'        => 255,
                'status'      => 1,
                'created_at'  => time()
            ],
            [
                'parent_id'   => $list_id,
                'name'        => '状态',
                'path'        => 'arts/manage/web_article/status',
                'action'      => 'status',
                'icon'        => 'el-icon-warning',
                'level'       => 2,
                'facility'    => 2,
                'sort'        => 255,
                'status'      => 1,
                'created_at'  => time()
            ]
        ]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('web_article');
    }
};
